package com.huanxing.cloud.miniapp.controller.app;

import com.huanxing.cloud.common.core.util.Result;
import com.huanxing.cloud.common.security.annotation.HxInner;
import com.huanxing.cloud.miniapp.api.dto.WxUserLoginReqDTO;
import com.huanxing.cloud.miniapp.api.dto.WxUserReqDTO;
import com.huanxing.cloud.miniapp.api.entity.WxUser;
import com.huanxing.cloud.miniapp.service.IWxUserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * 微信用户
 *
 * @author lijx
 * @since 2022/3/14 15:36
 */
@Slf4j
@AllArgsConstructor
@RestController
@RequestMapping("/app/wxuser")
@Tag(description = "app-wxuser", name = "微信用户-API")
public class AppWxUserController {

	private final IWxUserService wxUserService;

	@HxInner
	@Operation(summary = "微信小程序登录")
	@PostMapping("/ma/login")
	public Result<WxUser> login(@RequestBody @Valid WxUserLoginReqDTO wxUserLoginReqDTO) {
		return Result.success(wxUserService.login(wxUserLoginReqDTO));
	}

	@HxInner
	@Operation(summary = "解密手机号")
	@PostMapping("/ma/phone")
	public Result phone(@RequestBody @Valid WxUserLoginReqDTO wxUserLoginReqDTO) {
		return Result.success(wxUserService.decryptPhone(wxUserLoginReqDTO));
	}

	@HxInner
	@Operation(summary = "通过ID查询微信用户信息")
	@GetMapping("/{id}")
	public Result getById(@PathVariable String id) {
		return Result.success(wxUserService.getById(id));
	}

	@HxInner
	@Operation(summary = "绑定商城用户id")
	@PostMapping("/ma/bind")
	public Result<Boolean> bindUserId(@RequestBody WxUserReqDTO wxUserReqDTO) {
		return Result.success(wxUserService.bindUserId(wxUserReqDTO));
	}

	@Operation(summary = "解绑商城用户id")
	@PostMapping("/ma/unbind")
	public Result<Boolean> unbindUserId(@RequestBody WxUserReqDTO wxUserReqDTO) {
		return Result.success(wxUserService.unbindUserId(wxUserReqDTO));
	}

}
